<template>
  <div class="app-container">
    <div class="filter-container">
         <el-form ref="dataForm" :model="temp" label-position="right" label-width="130px" >
       
       
        <el-form-item label="认证收费" prop="authentication" name="authentication" >
          <!-- <el-input v-model="temp.authentication"  placeholder="用户认证资料时收费，0则不收费" /> -->
          <el-input-number v-model="temp.authentication" :min="0" :max="1000" />
           <span>用户认证资料时收费，0则不收费</span>
        </el-form-item>
    
         
        <el-form-item label="商家充值" prop="storeRecharge" name="storeRecharge">
     
            <template  >
                <el-input-number v-for="(item, index) in temp.storeRecharge" :key="index" v-model="temp.storeRecharge[index]"  :min="1" :max="100000" />
            </template>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
       
        <el-button type="primary" @click="createData()">
          提交
        </el-button>
      </div>
        </div>
        </div>
</template>



<script>
import { GQL } from '@/api/article'
export default {

  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
        temp:{
           sincerity:'',
           familyRecharge:'',
           authentication:'',
           storeRecharge:[]
        },
 

    }
  },
  created() {
     this.getList()
     
  },
  methods: {
 
    getList() {
        const query = {
               "operationName": "allSlSystemConfigs",
                "query":"query allSlSystemConfigs($filter: SlSystemConfigFilter) { allSlSystemConfigs(filter: $filter) { nodes { id authentication familyRecharge sincerity storeRecharge} } }",
                "variables":{ "filter": { "menuName":  { "equalTo": "site_name" } } }
        }
      
       GQL(query).then(response => {
        response.data.allSlSystemConfigs.nodes.forEach(element => {
            element.storeRecharge = JSON.parse(element.storeRecharge)
        });
        this.temp = response.data.allSlSystemConfigs.nodes[0]
        console.log('1111',this.temp )
        // console.log('11111-',this.temp)
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
      
    },
    createData(){
        this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const tempData = Object.assign({}, this.temp)
            tempData.storeRecharge = JSON.stringify(tempData.storeRecharge)
            // console.log('2===',tempData)
            let query = {
                "operationName": "updateSlSystemConfigById",
                "query": "mutation updateSlSystemConfigById($input: UpdateSlSystemConfigByIdInput!) { updateSlSystemConfigById(input: $input) { slSystemConfig { authentication familyRecharge sincerity id  } } }",
                "variables": {input: {id: tempData.id, slSystemConfigPatch:tempData}}
            }
            GQL(query).then((res) => {
                if(res.errors){
                    this.$notify({
                        title: '保存失败',
                        message: '保存设置失败',
                        type: 'error',
                        duration: 2000
                    })
                }else{
                    this.$notify({
                        title: '保存成功',
                        message: '保存设置成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                }
        
            })
        }
      })
    },

  }
}
</script>
<style scoped>
</style>
